<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Using Phar Archives: the phar stream wrapper</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phar.using.intro.html">Using Phar Archives: Introduction</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phar.using.object.html">Using Phar Archives: the Phar and PharData class</a></div>
 <div class="up"><a href="phar.using.html">Using Phar Archives</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="phar.using.stream" class="section">
 <h2 class="title">Using Phar Archives: the phar stream wrapper</h2>
 <p class="para">
  The Phar stream wrapper fully supports <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> for
  read and write (not append), <span class="function"><a href="function.unlink.html" class="function">unlink()</a></span>, <span class="function"><a href="function.stat.html" class="function">stat()</a></span>,
  <span class="function"><a href="function.fstat.html" class="function">fstat()</a></span>, <span class="function"><a href="function.fseek.html" class="function">fseek()</a></span>, <span class="function"><a href="function.rename.html" class="function">rename()</a></span>
  and directory stream operations <span class="function"><a href="function.opendir.html" class="function">opendir()</a></span> and as of version 2.0.0, <span class="function"><a href="function.rmdir.html" class="function">rmdir()</a></span>
  and <span class="function"><a href="function.mkdir.html" class="function">mkdir()</a></span>.
 </p>
 <p class="para">
  Individual file compression and per-file metadata can also be manipulated
  in a Phar archive using stream contexts:
 </p>
 <p class="para">
  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$context&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'phar'&nbsp;</span><span style="color: #007700">=&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'compress'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">GZ</span><span style="color: #007700">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'metadata'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(</span><span style="color: #DD0000">'user'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'cellog'</span><span style="color: #007700">)));<br /></span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar://my.phar/somefile.php'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </p>
 <p class="para">
  The <em>phar</em> stream wrapper does not operate on remote files,
  and cannot operate on remote files, and so is allowed even when the
  <a href="filesystem.configuration.html#ini.allow-url-fopen" class="link">allow_url_fopen</a> and
  <a href="filesystem.configuration.html#ini.allow-url-include" class="link">allow_url_include</a> INI options
  are disabled.
 </p>
 <p class="para">
  Although it is possible to create phar archives from scratch just using
  stream operations, it is best to use the functionality built into
  the Phar class.  The stream wrapper is best used for read-only operations.
 </p>
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phar.using.intro.html">Using Phar Archives: Introduction</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phar.using.object.html">Using Phar Archives: the Phar and PharData class</a></div>
 <div class="up"><a href="phar.using.html">Using Phar Archives</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
